package com.modifiertech.lineage.client.gui.ftbint;

import com.feed_the_beast.ftblib.lib.gui.Panel;
import com.feed_the_beast.ftblib.lib.gui.PanelScrollBar;
import com.feed_the_beast.ftblib.lib.gui.TextField;
import com.feed_the_beast.ftblib.lib.gui.Theme;
import com.feed_the_beast.ftblib.lib.icon.Color4I;
import com.modifiertech.lineage.Lineage;
import com.modifiertech.lineage.api.PlayerData;
import com.modifiertech.lineage.event.PlayerDataHandler;

public class PanelFootConsole extends Panel {
    private GuiLineageV2 mainGui;
    private Panel textPanel;
    private TextField textField;
    private PanelScrollBar scrollH,scrollV;

    public PlayerData playerDataRelClient;
    public PanelFootConsole(Panel panel, GuiLineageV2 mainGui) {
        super(panel);
        this.mainGui=mainGui;
        initialize();
    }

    public void initialize() {
        initPlayerData();
        initAttrString();
        initAttrOptBtn();
    }
    private void initPlayerData() {
        this.playerDataRelClient = PlayerDataHandler.get(Lineage.proxy.getClientPlayer());
    }
    private void initAttrOptBtn() {
    }
    private void initAttrString() {
        PlayerData data = PlayerDataHandler.get(Lineage.proxy.getClientPlayer());
        textPanel = new Panel(this) {
            @Override
            public void addWidgets() {
                add(textField);
            }

            @Override
            public void alignWidgets() {
                scrollH.setMaxValue(textField.width + 4);
                scrollV.setMaxValue(textField.height);
            }
            @Override
            public void drawBackground(Theme theme, int x, int y, int w, int h) {
                Color4I.BLACK.withAlpha(60).draw(x, y, w, h);
            }
        };
        textField=new TextField(textPanel);
        textField.setX(2);
        textField.addFlags(Theme.UNICODE);
        textField.setText("console");
        textField.setScale(1f);
        textPanel.setPos(5,5);
        textPanel.setUnicode(true);
        scrollH=new PanelScrollBar(this,PanelScrollBar.Plane.HORIZONTAL,textPanel);
        scrollH.setCanAlwaysScroll(false);
        scrollH.setCanAlwaysScrollPlane(false);
        scrollH.setScrollStep(10);
        scrollV = new PanelScrollBar(this, textPanel);
        scrollV.setCanAlwaysScroll(false);
        scrollV.setCanAlwaysScrollPlane(false);
        scrollV.setScrollStep(10);
//        scrollH.setValue(0);
//        scrollV.setValue(0);

    }

    @Override
    public void tick() {
        super.tick();
        //render attribute
//        renderAttribute();
    }

    public void setSkillDescription(String skillInfo){
        this.textField.setText(skillInfo);
        scrollH.setValue(0);
        scrollV.setValue(0);
        alignWidgets();
    }

    private void renderAttribute() {
        scrollV.setValue(scrollV.getMaxValue());
//        PlayerData data = PlayerDataHandler.get(Lineage.proxy.getClientPlayer());
//        if(null!=data){
//            //Total skill point
////            this.textFieldSkillDescription.setText(data.getSkillPointTotal()+"");
//            //Undistributed skill point
////            this.getTextFieldSkillPointDistributedValue().setText(data.getSkillPointUndistributed()+"");
//        }

    }

    @Override
    public void addWidgets() {
        add(textPanel);
        add(scrollH);
        add(scrollV);
    }

    @Override
    public void alignWidgets() {
        scrollH.setPosAndSize(5, height - 10, width - 10, 10);
        scrollV.setPosAndSize(width - 5, 5, 5, height - 5);
        textPanel.setSize(scrollH.width - 2, scrollV.height - 2);
        textPanel.alignWidgets();
        renderAttribute();
    }

    @Override
    public void drawBackground(Theme theme, int x, int y, int w, int h) {
        Color4I.WHITE.withAlpha(50).withBorder(Color4I.BLACK,true).draw(x, y, w, h);
//        theme.drawPanelBackground(x, y, w, h);
    }


    public TextField getTextField() {
        return textField;
    }

    public void setTextField(TextField textField) {
        this.textField = textField;
    }

    public Panel getTextPanel() {
        return textPanel;
    }

    public void setTextPanel(Panel textPanel) {
        this.textPanel = textPanel;
    }
}
